<template>
  <div class="m-head">
    <el-row>
      <el-col :span="12" class="logo-container">
        <img src="../assets/images/logo.png" class="logo" />
        <span class="title">后台管理系统</span>
      </el-col>
      <el-col :span="12" class="user">
        <div class="userinfo">
          <img :src="user.avatar" class="avatar" />
          <div class="welcome">
            <p class="name comename">欢迎</p>
            <p class="name avatarname">{{ user.name }}</p>
          </div>
          <!-- 下拉菜单 -->
          <span class="usernam">
            <el-dropdown @command="setDialogInfo" trigger="click">
              <span class="el-dropdown-link">
                <i class="el-icon-caret-bottom el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="info">个人信息</el-dropdown-item>
                <el-dropdown-item command="logout">退出</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </span>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'm-head',
  computed: {
    user () {
      return this.$store.getters.user
    }
  },
  methods: {
    setDialogInfo (command) {
      switch (command) {
        case 'info':
          this.showInfoList()
          break
        case 'logout':
          this.logout()
          break
      }
    },
    showInfoList () {
      this.$router.push('/index/infoShow')
    },
    logout () {
      // 清除token
      localStorage.removeItem('manageSystemToken')
      // 设置vuex store
      this.$store.dispatch('clearCurentState')
      // 跳转到登录页
      this.$router.push('/login')
    }
  }
}
</script>

<style lang="stylus" scoped>

.m-head {
  width: 100%;
  height: 60px;
  min-width: 800px;
  padding: 5px;
  background: #324057;
  color: #fff;
  border-bottom: 1px solid #1f2d3d;

  .logo-container {
    line-height: 60px;
    min-width: 400px;

    .logo {
      height: 50px;
      width: 50px;
      margin-right: 5px;
      vertical-align: middle;
      display: inline-block;
    }
    .title {
      vertical-align: middle;
      font-size: 22px;
      font-family: 'Microsoft YaHei';
      letter-spacing: 3px;
    }
  }

  .user {
    line-height: 60px;
    text-align: right;
    float: right;
    padding-right: 10px;
    .avatar {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      vertical-align: middle;
      display: inline-block;
    }
    .welcome {
      display: inline-block;
      width: auto;
      vertical-align: middle;
      padding: 0 5px;
      .name {
        line-height: 20px;
        text-align: center;
        font-size: 14px;
      }
      .comename {
        font-size: 12px;
      }
      .avatarname {
        color: #409eff;
        font-weight: bolder;
      }

    }
    .el-dropdown {
      color: #fff;
    }
    .username {
      cursor: pointer;
      margin-right: 5px;
    }
  }

}
</style>
